package com.zbkj.front.controller.employee;

import com.alipay.api.domain.PageInfo;
import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.product.ProductCategory;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.ProductCategoryRequest;
import com.zbkj.common.response.MerchantOrderPageResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.vo.ProCategoryCacheVo;
import com.zbkj.service.service.ProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 小程序商品分类控制器
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/front/employee/product/category")
@Api(tags = "商品分类控制器")
public class EmployeeProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @ApiOperation(value = "商品分类列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProductCategory>> getList(ProductCategory category, PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(productCategoryService.getXcxAdminList(category, pageParamRequest)));
    }

    @ApiOperation(value = "商品分类名称精准搜索列表")
    @RequestMapping(value = "/accuracyList", method = RequestMethod.GET)
    public CommonResult<CommonPage<ProductCategory>> getAccuracyList(ProductCategory category, PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(productCategoryService.getXcxAccuracyAdminList(category, pageParamRequest)));
    }

    @ApiOperation(value = "商品分类缓存树")
    @RequestMapping(value = "/cache/tree", method = RequestMethod.GET)
    public CommonResult<List<ProCategoryCacheVo>> getPlatformCacheTree() {
        return CommonResult.success(productCategoryService.getCacheTree(1));
    }

    @ApiOperation(value = "商品分类三层缓存树")
    @RequestMapping(value = "/cache/treeOnlyThree", method = RequestMethod.GET)
    public CommonResult<List<ProCategoryCacheVo>> getPlatformCacheTreeOnlyThree() {
        return CommonResult.success(productCategoryService.getCacheTreeOnlyThree(1));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.ADD, description = "新增商品分类")
    @ApiOperation(value = "新增商品分类")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult<String> add(@RequestBody @Validated ProductCategoryRequest request) {
        request.setIsShow(0);
        if (productCategoryService.add(request)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation(value = "子级查询父级分类信息")
    @RequestMapping(value = "/getParentCategory", method = RequestMethod.GET)
    public CommonResult<List<ProductCategory>> getParentCategory(ProductCategory category) {
        List<ProductCategory> categoryParentList = productCategoryService.findAllParentListByPid(category.getId());
        return CommonResult.success(categoryParentList);
    }
}



